#!/bin/bash
# 安装hb
baseDirForScriptSelf=$(cd "$(dirname "$0")"; pwd)
source ${baseDirForScriptSelf}/source.sh
cd ${work_dir}/OpenHarmony
unset http_proxy
unset https_proxy
is_huawei_tmp=`curl -I -m 10 -o /dev/null -s -w %{http_code} w3.huawei.com`
if [ "${is_huawei_tmp}" == "200" ];then
    is_huawei=true
else
    is_huawei=false
fi
## 内网不需要配置代理
if [ "${is_huawei}" == "true" ];then
    unset http_proxy;unset https_proxy
else
    source  ${baseDirForScriptSelf}/proxy.sh
fi
python3.8 -m pip install --user --upgrade ohos-build >>${baseDirForScriptSelf}/init_run.log 2>&1
if [ ! -d ~/.local/ ];then
    echo  -e "${failed_color},hb install failed,dir '~/.local/' not exist,Please check!"
else
    BIN_PATH=~/.local/bin
sudo bash -c "echo 'export PATH=~/.local/bin:\$PATH' >/etc/profile.d/hb.sh"
    source /etc/profile
    source /etc/profile.d/hb.sh
fi
hb_version=`hb --version`
if [ $? -gt 0 ];then
    echo  -e "${failed_color},hb install failed.Please check!"
    exit 1
else
    echo  -e "${success_color},hb install success.version:${hb_version}"
fi
